<template>
  <div class="userinfo">
    <div class="userinfo-top same">
      <div class="avatar-info">
        <el-avatar id="avatar" :size="80" :src="circleUrl" />
        <div class="name">
          <p>
            {{ userStore.userInfoDetail?.username ? userStore.userInfoDetail?.username : '用户名' }}
          </p>
          <span>{{ userStore.userInfoDetail?.role === 0 ? '超级管理员' : '用户' }}</span>
        </div>
      </div>
      <div class="more">
        <ul>
          <li>
            上次登录时间：<span>{{ formateDate(userStore.userInfoDetail?.updatetime) }}</span>
          </li>
          <li>上次登录地点：<span>江苏</span></li>
        </ul>
      </div>
    </div>
    <div class="userinfo-bottom same">
      <h1 class="title">语言详情</h1>
      <div class="scroll">
        <div class="bar" v-for="item in barData" :key="item">
          <div class="name">{{ item.name }}</div>
          <div class="value">
            <div
              class="value-bar"
              :style="{ backgroundColor: item.color, width: item.width }"
            ></div>
          </div>
          <span>{{ item.value }}%</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useUserStore } from '@/store/userStore'
import { formateDate } from '@/utils/formatTime'
import { computed } from 'vue'
const userStore = useUserStore()
const barData: any = [
  { name: 'Vue', value: 80, color: 'red', width: '80%' },
  { name: 'React', value: 70, color: 'skyblue', width: '70%' },
  { name: 'Angular', value: 50, color: 'green', width: '50%' },
  { name: 'Ember', value: 30, color: 'orange', width: '30%' }
]
// 默认显示头像
const circleUrl = computed(() => {
  return userStore.userInfoDetail?.avatar
    ? `${import.meta.env.VITE_BASE_URL}upload/${userStore.userInfoDetail?.avatar}`
    : 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'
})
</script>

<style lang="scss" scoped>
.same {
  border: 1px solid #ccc;
  background-color: #fff;
  border-radius: 3px;
  transition: all 0.3s;
}
.userinfo {
  .userinfo-top {
    margin-bottom: 20px;
    .avatar-info {
      padding: 20px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      border-bottom: 1px solid #ccc;

      .name {
        p {
          font-size: 20px;
          font-weight: 600;
        }
        span {
          font-size: 16px;
          color: #ccc;
        }
      }
    }
    .more {
      padding: 20px;
      li {
        list-style: none;
        padding: 5px;
        font-size: 14px;
        color: #ccc;
      }
    }
  }
  .userinfo-bottom {
    h1 {
      padding: 20px;
      border-bottom: 1px solid #ccc;
      &.title {
        font-size: 20px;
        font-weight: 500;
      }
    }
    .scroll {
      padding: 20px;
      .bar {
        .value {
          position: relative;
          display: inline-block;
          width: 90%;
          height: 10px;
          border-radius: 10px;
          background-color: rgb(235, 238, 245);
          .value-bar {
            position: absolute;
            top: 0;
            left: 0;
            display: inline-block;
            /* background-color: red; */
            /* width: 50%; */
            height: 100%;
            border-radius: 10px;
          }
        }
      }
    }
  }
}
</style>
